package com.hhkj.study.admin.article.service.biz.impl;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.hhkj.study.admin.article.entity.ArticleBanner;
import com.hhkj.study.admin.article.entity.ArticleCatalog;
import com.hhkj.study.admin.article.model.podo.ArticleCatalogDo;
import com.hhkj.study.admin.article.model.podo.ArticleCatalogPo;
import com.hhkj.study.admin.article.model.req.ArticleCatalogReq;
import com.hhkj.study.admin.article.model.res.ArticleCatalogRes;
import com.hhkj.study.admin.article.service.base.ArticleCatalogService;
import com.hhkj.study.admin.article.service.biz.ArticleCatalogBizService;
import com.hhkj.study.admin.article.service.extend.ArticleCatalogExtendService;
import com.ruoyi.common.base.biz.service.biz.BaseBizServiceImpl;
import com.ruoyi.common.cont.SysConst;
import com.ruoyi.common.exception.GlobalException;
import org.springframework.stereotype.Service;

/**
* ArticleCatalogBizServiceImpl
*
* @author SERVER
* @since 2024-09-06
*/
@Service
public class ArticleCatalogBizServiceImpl extends BaseBizServiceImpl<ArticleCatalog, ArticleCatalogReq, ArticleCatalogRes, ArticleCatalogDo, ArticleCatalogPo, ArticleCatalogService, ArticleCatalogExtendService> implements ArticleCatalogBizService {
    @Override
    public boolean updatePublishFlag(ArticleCatalogReq req) {
        ArticleCatalog articleCatalog = this.getExtendService().getByIdNotNull(req.getId());
        if (articleCatalog.getPublishedFlag().equals(req.getPublishedFlag())) {
            throw new GlobalException(SysConst.Flag.IS.getFlag().equals(req.getPublishedFlag()) ?
                    "已上架" : "已下架");
        }
        LambdaUpdateWrapper<ArticleCatalog> catalogUpdate = new LambdaUpdateWrapper<>();
        catalogUpdate.eq(ArticleCatalog::getId, req.getId())
                .set(ArticleCatalog::getPublishedFlag, req.getPublishedFlag());
        return this.getService().update(catalogUpdate);
    }
}